<template>
	<view class="friend">
		<view class="purchase">
			<Singlestore :query="iniviteQuery.shop_info"></Singlestore>
			<view class="switchover_btn" @click="routeChangeshop">
				<image :src="$IMG_URL('/static/newVersion/cut.png')" mode="aspectFill" class="cut"></image>
				<text>切换门店</text>
			</view>
		</view>
		<view class="swiper">
			<u-swiper :list="iniviteQuery.deploy_info.image_list" height="270" mode="rect" interval="5000"></u-swiper>
		</view>
		<!-- 优化后的邀请数据卡片 -->
		<view class="card optimized-card" @click="handleCardClick">
			<!-- <view class="rule" @click="routeRules">
				邀请规则
			</view> -->
			<view class="top_box">
				<view class="item">
					<view class="child_csm br">
						<view class="stat-header">
							<u-icon name="account" color="#73F0EA" size="24"></u-icon>
							<view class="stat-label">邀请人数</view>
						</view>
						<view class="top">
							<view class="num">
								{{iniviteQuery.user_num}}
							</view>
							<view class="unit">
								人
							</view>
						</view>
						<view class="content">
							已邀请好友
						</view>
					</view>
				</view>
				<view class="item">
					<view class="child_csm">
						<view class="stat-header">
							<u-icon name="clock" color="#73F0EA" size="24"></u-icon>
							<view class="stat-label">健身时长</view>
						</view>
						<view class="top">
							<view class="num">
								{{iniviteQuery.invite_info.duration_days}}
							</view>
							<view class="unit">
								天
							</view>
						</view>
						<view class="content">
							已获得健身时长
						</view>
					</view>
				</view>
			</view>
			<view class="bottom_box">
				<view class="qrcode-wrapper">
					<u-image :src="iniviteQuery.invite_info.invite_qrcode" mode="aspectFill" width="280rpx" height="280rpx"
						:loading-icon="$IMG_URL('/static/loading/loading.gif')" :lazy-load="true"
						@click.stop="$PREVIEW_IMAGE(iniviteQuery.invite_info.invite_qrcode)" class="qrcode-image">
					</u-image>
					<view class="preview-tip">
						<u-icon name="eye" color="#ffffff" size="20"></u-icon>
						<text class="tip-text">点击预览</text>
					</view>
				</view>
				<view class="share-tip">
					<u-icon name="arrow-upward" color="#73F0EA" size="20"></u-icon>
					<text class="tip-text">点击分享给好友</text>
				</view>
			</view>
		</view>
		<view class="rights-and-interests-b">
			<u-parse :html="iniviteQuery.deploy_info.content" :selectable="true"></u-parse>
		</view>
		<!-- 恢复原始的邀请记录 -->
		<view class="card2">
			<view class="tabs">
				<view v-for="(item,index) in tabsList" :key="index" class="tabItem" @click="changeTabs(index)">
					<view class="size"
						:style="{color:TabsCurrent == index ?'#73F0EA':'#999999',fontWeight:TabsCurrent == index ?'800':'400'}">
						{{item.name}}
					</view>
					<view class="sliding-block-box">
						<view class="sliding-block-child" v-if="TabsCurrent == index">

						</view>
					</view>

				</view>
			</view>
			<view class="cardFoot">
				<scroll-view scroll-y="true" class="scroll-Y">
					<view class="comlum_Y" v-if="list.length">
						<view v-for="(item,index) in !TabsCurrent? iniviteQuery.user_list:iniviteQuery.buy_list" :key="index"
							class="item">
							<view class="left">
								<image :src="item.avatar" mode="aspectFill" class="img avatar"></image>
								<view class="name">
									{{item.nickname}}
								</view>
							</view>
							<view class="time-text">
								<view class="time">{{item.time}}</view>
								<view class="state">
									{{item.state_str}}
								</view>
							</view>
						</view>
					</view>
					<empty v-else :content="!TabsCurrent?'邀请好友':'好友购卡'"></empty>
				</scroll-view>
			</view>
		</view>
		<view class="empty-box">

		</view>
		<view class="foot">
			<view class="btn" @click="$ROUTELINK('share?invite_id=' + iniviteQuery.invite_info.invite_id)">
				分享给好友
			</view>
		</view>
		<WechatCode :WechatCodeShow="WechatCodeShow" :code="wechatCode" @sure="weChatSure" @save="save" :title="'面对面送卡'"
			:content="'邀请好友领取体验卡'" :btn="'关闭'"></WechatCode>

	</view>
</template>

<script>
	import WechatCode from '@/components/WechatCode.vue'
	import Singlestore from '@/components/Singlestore.vue'
	import empty from '../components/emptyTwo.vue'
	import {
		inviteMain
	} from '@/api/user.js'
	export default {
		components: {
			WechatCode,
			Singlestore,
			empty
		},
		data() {
			return {
				query: {

				},
				iniviteQuery: {},
				// 微信二维码弹窗
				WechatCodeShow: false,
				wechatCode: 'https://file.digitaling.com/eImg/uimages/20150818/1439870276584955.gif',
				swiperList: [],
				tabsList: [{
						name: '邀请好友'
					},
					{
						name: '好友购卡'
					}
				],
				TabsCurrent: 0,
				list: [],
				rules: {}
			}
		},
		onLoad() {
			this.getInviteMain()
		},
		onShow() {
			let that = this
			uni.$on('SHOPID', function(data) {
				console.log("SHOPID：", data);
				that.getInviteMain({
					shop_id: data.shop_id
				})
			})
		},
		methods: {
			routeRules() {
				uni.navigateTo({
					url: '/pageA/agreement/rules'
				})
			},
			getInviteMain(e) {
				inviteMain(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.iniviteQuery = res.data
						this.list = res.data.user_list
						this.tabsList[0].name = '邀请好友(' + res.data.user_num + ')'
						this.tabsList[1].name = '好友购卡(' + res.data.buy_num + ')'
					}
				})
			},
			routeChangeshop() {
				uni.navigateTo({
					url: '/pageA/shop/select'
				})
			},
			changeTabs(index) {
				if (this.TabsCurrent != index) {
					this.TabsCurrent = index
					if (!index) {
						this.list = this.iniviteQuery.user_list
					} else {
						this.list = this.iniviteQuery.buy_list
					}
				}
			},
			weChatSure() {
				this.WechatCodeShow = false
			},
			save() {
				this.$SAVERIMG(this.wechatCode)
				this.WechatCodeShow = false
			}
		}
	}
</script>

<style lang="scss">
	.rights-and-interests-b {
		width: 702rpx;
		border-radius: 16rpx;
		margin-top: 24rpx;
		background-color: #ffffff;
	}

	page {
		background: #e9e9e9;
	}

	.friend {
		display: flex;
		flex-direction: column;
		align-items: center;

		.purchase {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
			height: 324rpx;
			background: #ffffff;

			.switchover_btn {
				transform: rotateZ(360deg);
				width: 702rpx;
				height: 88rpx;
				border: 1rpx solid #73F0EA;
				border-radius: 16rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				color: #73F0EA;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: row;

				.cut {
					width: 24rpx;
					height: 24rpx;
					margin-right: 8rpx;
				}
			}
		}

		.swiper {
			margin-top: 24rpx;
			width: 702rpx;
			height: 270rpx;
		}

		.card {
			margin-top: 24rpx;
			width: 702rpx;
			background: #ffffff;
			border-radius: 16rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			overflow: hidden;
			position: relative;
			box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.05);
			transition: all 0.3s ease;

			&.optimized-card {
				background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
				border: 1rpx solid #f0f0f0;
			}

			.rule {
				position: absolute;
				right: 0;
				top: 0;
				width: 128rpx;
				height: 42rpx;
				background: rgba(129, 202, 197, 0.1);
				border-radius: 0rpx 16rpx 0rpx 16rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC-Medium;
				font-weight: 500;
				color: #73F0EA;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.top_box {
				display: flex;
				flex-direction: row;
				align-items: center;
				width: 638rpx;
				padding: 40rpx 0;
				border-bottom: 1rpx solid #f0f0f0;
			}

			.bottom_box {
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 40rpx 0 60rpx;
				width: 100%;

				.qrcode-wrapper {
					position: relative;
					border: 1rpx solid #f0f0f0;
					border-radius: 16rpx;
					padding: 20rpx;
					background: #fafafa;
					transition: all 0.3s ease;

					&:active {
						transform: scale(0.98);
					}

					.qrcode-image {
						border-radius: 8rpx;
					}

					.preview-tip {
						position: absolute;
						top: 20rpx;
						right: 20rpx;
						background: rgba(0, 0, 0, 0.6);
						border-radius: 20rpx;
						padding: 8rpx 16rpx;
						display: flex;
						align-items: center;
						gap: 6rpx;

						.tip-text {
							color: #ffffff;
							font-size: 20rpx;
							font-weight: 500;
						}
					}
				}

				.share-tip {
					display: flex;
					align-items: center;
					gap: 8rpx;
					margin-top: 20rpx;
					padding: 10rpx 20rpx;
					background: rgba(115, 240, 234, 0.1);
					border-radius: 30rpx;
					transition: all 0.3s ease;

					&:active {
						background: rgba(115, 240, 234, 0.2);
					}

					.tip-text {
						color: #73F0EA;
						font-size: 24rpx;
						font-weight: 500;
					}
				}
			}

			.item {
				width: 350.5rpx;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;

				.br {
					border-right: 1rpx solid #e9e9e9;
				}


				.child_csm {
					width: 100%;
					display: flex;
					flex-direction: column;
					align-items: center;

					.stat-header {
						display: flex;
						align-items: center;
						gap: 8rpx;
						margin-bottom: 16rpx;

						.stat-label {
							font-size: 24rpx;
							font-weight: 500;
							color: #999999;
						}
					}

					.top {
						display: flex;
						flex-direction: row;
						align-items: baseline;
						margin-bottom: 12rpx;

						.num {
							font-size: 48rpx;
							font-family: DIN, DIN-Bold;
							font-weight: 700;
							text-align: left;
							color: #333333;
						}

						.unit {
							font-size: 24rpx;
							font-family: DIN, DIN-Bold;
							font-weight: 700;
							text-align: left;
							color: #333333;
							margin-left: 4rpx;
						}
					}

					.content {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: center;
						color: #666666;
					}
				}
			}
		}

		.card2 {
			margin-top: 24rpx;
			width: 702rpx;
			height: 770rpx;
			background: #ffffff;
			border-radius: 16rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.05);
			transition: all 0.3s ease;

			&.optimized-card {
				background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
				border: 1rpx solid #f0f0f0;
			}

			.tabs {
				margin-top: 30rpx;
				height: 60rpx;
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-around;
				border-bottom: 1rpx solid #e9e9e9;

				.tabItem {
					display: flex;
					flex-direction: column;
					align-items: center;
					height: 60rpx;
					cursor: pointer;
					transition: all 0.2s ease;

					.size {
						font-size: 32rpx;
						letter-spacing: 0.62rpx;
						font-family: PingFang SC, PingFang SC-Heavy;
					}

					.sliding-block-box {
						height: 20rpx;
						padding-top: 12rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
					}

					.sliding-block-child {
						width: 44rpx;
						height: 8rpx;
						background: #73F0EA;
						border: 2rpx solid rgba(0, 0, 0, 0.00);
						border-radius: 2rpx;
					}
				}
			}

			.cardFoot {
				flex: 1;
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;

				.scroll-Y {
					height: 100%;
					width: 100%;
				}

				.comlum_Y {
					padding: 32rpx;
					width: 100%;
					display: flex;
					flex-direction: column;
					align-items: center;
				}

				.item {
					display: flex;
					flex-direction: row;
					align-items: center;
					width: 100%;
					margin-bottom: 32rpx;
					padding: 24rpx;
					border-radius: 12rpx;
					background: #fafafa;
					transition: all 0.2s ease;
          justify-content:space-between;
					&.optimized-item {
						&:hover {
							background: #f5f5f5;
							transform: translateY(-2rpx);
							box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
						}
					}

					.time-text {
						display: flex;
						align-items: center;
					  flex-direction:column;
						text-align: right;

					}


					.left {
						display: flex;
						flex-direction: row;
						align-items: center;
						// flex: 1;

						.img {
							width: 70rpx;
							height: 70rpx;
							background: #f6f6f6;
							border-radius: 50%;
							margin-right: 16rpx;
						}

						.avatar {
							border: 2rpx solid #73F0EA;
						}

						.name {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Medium;
							font-weight: 500;
							text-align: left;
							color: #333333;
						}
					}

					.time {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: right;
						color: #999999;
						margin: 0 16rpx;
					}

					.status-badge {
						font-size: 22rpx;
						font-weight: 500;
						padding: 6rpx 16rpx;
						border-radius: 20rpx;
						background: #f0f0f0;
						color: #666666;

						&.success {
							background: rgba(115, 240, 234, 0.15);
							color: #73F0EA;
						}

						&.pending {
							background: rgba(255, 184, 0, 0.15);
							color: #ffb800;
						}

						&.expired {
							background: rgba(255, 100, 100, 0.15);
							color: #ff6464;
						}
					}
				}
			}
		}

		.empty-box {
			width: 100%;
			height: 180rpx;
		}

		.foot {
			width: 750rpx;
			height: 160rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(166, 179, 194, 0.30);
			display: flex;
			justify-content: center;
			padding-top: 10rpx;
			position: fixed;
			bottom: 0;

			.btn {
				width: 710rpx;
				height: 88rpx;
				background: #73F0EA;
				border-radius: 16rpx;
				font-size: 34rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: center;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>